package fctuc.dei.myTwitter.com;

import java.io.Serializable;
import java.util.Hashtable;



public class Message implements Serializable {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public int id = -1;
    public MT type;
    private Hashtable<String, Object> props;

    public Message(int id, MT type, Object... props) {
        this(type, props);
        this.id = id;
    }

    public Message(MT type, Object... args) {
        assert args.length % 2 == 0; 
        this.type = type; 
        props = new Hashtable<String, Object>();
        for (int i = 0; i < args.length; i += 2)
            props.put((String) args[i], args[i+1]);
    }

    public void set(String name, Object obj) {
        props.put(name, obj);
    }
    
    public Object get(String name) {
        return props.get(name);
    }
    
    public String getStr(String name) {
        return (String) props.get(name);
    }

    public Integer getInt(String name) {
        Object obj = props.get(name);
        if (obj instanceof Integer)
            return (Integer) obj;
        else
            return new Integer((String) obj);
    }

    public boolean existsStr(String name){
        return props.containsKey(name);
    }

    public String[] getStrArr(String name) {
        return (String[]) props.get(name);
    }

    public String toString() {
        return "MSG(" + id + "): " + type + " " + props;
    } 
}
